package com.zty.xiaomiadmin.server.Dao;


import com.zty.xiaomiadmin.server.Entity.Report.Report;
import com.zty.xiaomiadmin.server.Entity.Report.ReportPie;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

public interface ReportMapper {

    @Select("SELECT SUBSTRING(createTime,1,10) createTime,payment FROM orde GROUP BY SUBSTRING(createTime,1,10)")
    List<Report> getMonthData();

    @Select("SELECT SUBSTRING(createTime,1,10) createTime,payment FROM orde where SUBSTRING(createTime,1,7) = #{date} and statusDesc ='交易成功' GROUP BY SUBSTRING(createTime,1,10)")
    List<Report> getReportDataByMonth(String date);

    @Select("SELECT SUBSTRING(createTime,1,10) createTime,payment FROM orde where SUBSTRING(createTime,1,7) = #{date} and statusDesc ='已支付' GROUP BY SUBSTRING(createTime,1,10)")
    List<Report> getReportDataByMonthPay(String date);

    @Select("SELECT SUBSTRING(createTime,1,10) createTime,payment FROM orde where SUBSTRING(createTime,1,7) = #{date} and statusDesc ='已取消' GROUP BY SUBSTRING(createTime,1,10)")
    List<Report> getReportDataByMonthCancel(String date);


    @Select("SELECT SUM(payment) value FROM orde WHERE SUBSTRING(createTime,1,7) = #{date} AND statusDesc='交易成功' GROUP BY SUBSTRING(createTime,1,7)")
    ReportPie getReportDataByMonthPaymentTotalAccess(String date);

    @Select("SELECT SUM(payment) value FROM orde WHERE SUBSTRING(createTime,1,7) = #{date} AND statusDesc='已支付' GROUP BY SUBSTRING(createTime,1,7)")
    ReportPie getReportDataByMonthPaymentTotalPay(String date);

    @Select("SELECT SUM(payment) value FROM orde WHERE SUBSTRING(createTime,1,7) = #{date} AND statusDesc='已取消' GROUP BY SUBSTRING(createTime,1,7)")
    ReportPie getReportDataByMonthPaymentTotalCancel(String date);

    @Select("SELECT SUBSTRING(createTime,1,7) createTime,SUM(payment) payment FROM orde WHERE SUBSTRING(createTime,1,4) = #{date} AND statusDesc ='交易成功' GROUP BY SUBSTRING(createTime,1,4)")
    List<Report> getReportDataByYear(String date);

    @Select("SELECT SUBSTRING(createTime,1,7) createTime,SUM(payment) payment FROM orde WHERE SUBSTRING(createTime,1,4) = #{date} AND statusDesc ='已支付' GROUP BY SUBSTRING(createTime,1,4)")
    List<Report> getReportDataByYearPay(String date);

    @Select("SELECT SUBSTRING(createTime,1,7) createTime,SUM(payment) payment FROM orde WHERE SUBSTRING(createTime,1,4) = #{date} AND statusDesc ='已取消' GROUP BY SUBSTRING(createTime,1,4)")
    List<Report> getReportDataByYearCancel(String date);

    @Select("SELECT SUM(payment) value FROM orde WHERE SUBSTRING(createTime,1,4) = #{date} AND statusDesc='交易成功' GROUP BY SUBSTRING(createTime,1,4)")
    ReportPie getReportDataByYearPaymentTotalAccess(String date);

    @Select("SELECT SUM(payment) value FROM orde WHERE SUBSTRING(createTime,1,4) = #{date} AND statusDesc='已支付' GROUP BY SUBSTRING(createTime,1,4)")
    ReportPie getReportDataByYearPaymentTotalPay(String date);

    @Select("SELECT SUM(payment) value FROM orde WHERE SUBSTRING(createTime,1,4) = #{date} AND statusDesc='已取消' GROUP BY SUBSTRING(createTime,1,4)")
    ReportPie getReportDataByYearPaymentTotalCancel(String date);
}
